home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 52 / Amiga Format AFCD52 (Issue 136, May 2000).iso / -serious- / programming / c / icu-1.3.1 / icu-bin / include / calendar.h < prev    next >
C/C++ Source or Header  |  2000-02-23  |  41KB  |  994 lines

  1. /*
  2. ********************************************************************************
  3. *                                                                              *
  4. * COPYRIGHT:                                                                   *
  5. *   (C) Copyright Taligent, Inc.,  1997                                        *
  6. *   (C) Copyright International Business Machines Corporation,  1997-1999      *
  7. *   Licensed Material - Program-Property of IBM - All Rights Reserved.         *
  8. *   US Government Users Restricted Rights - Use, duplication, or disclosure    *
  9. *   restricted by GSA ADP Schedule Contract with IBM Corp.                     *
  10. *                                                                              *
  11. ********************************************************************************
  12. *
  13. * File CALENDAR.H
  14. *
  15. * Modification History:
  16. *
  17. *   Date        Name        Description
  18. *   04/22/97    aliu        Expanded and corrected comments and other header
  19. *                           contents.
  20. *   05/01/97    aliu        Made equals(), before(), after() arguments const.
  21. *   05/20/97    aliu        Replaced fAreFieldsSet with fAreFieldsInSync and
  22. *                           fAreAllFieldsSet.
  23. *    07/27/98    stephen        Sync up with JDK 1.2
  24. ********************************************************************************
  25. */
  26.  
  27. #ifndef CALENDAR_H
  28. #define CALENDAR_H
  29.  
  30. #include "locid.h"
  31. #include "timezone.h"
  32.  
  33.  
  34.  
  35. /**
  36.  * <code>Calendar</code> is an abstract base class for converting between
  37.  * a <code>UDate</code> object and a set of integer fields such as
  38.  * <code>YEAR</code>, <code>MONTH</code>, <code>DAY</code>, <code>HOUR</code>,
  39.  * and so on. (A <code>UDate</code> object represents a specific instant in
  40.  * time with millisecond precision. See
  41.  * {@link UDate}
  42.  * for information about the <code>UDate</code> class.)
  43.  *
  44.  * <p>
  45.  * Subclasses of <code>Calendar</code> interpret a <code>UDate</code>
  46.  * according to the rules of a specific calendar system. The JDK
  47.  * provides one concrete subclass of <code>Calendar</code>:
  48.  * <code>GregorianCalendar</code>. Future subclasses could represent
  49.  * the various types of lunar calendars in use in many parts of the world.
  50.  *
  51.  * <p>
  52.  * Like other locale-sensitive classes, <code>Calendar</code> provides a
  53.  * class method, <code>getInstance</code>, for getting a generally useful
  54.  * object of this type. <code>Calendar</code>'s <code>getInstance</code> method
  55.  * returns a <code>GregorianCalendar</code> object whose
  56.  * time fields have been initialized with the current date and time:
  57.  * <blockquote>
  58.  * <pre>
  59.  * Calendar rightNow = Calendar.getInstance();
  60.  * </pre>
  61.  * </blockquote>
  62.  *
  63.  * <p>
  64.  * A <code>Calendar</code> object can produce all the time field values
  65.  * needed to implement the date-time formatting for a particular language
  66.  * and calendar style (for example, Japanese-Gregorian, Japanese-Traditional).
  67.  *
  68.  * <p>
  69.  * When computing a <code>UDate</code> from time fields, two special circumstances
  70.  * may arise: there may be insufficient information to compute the
  71.  * <code>UDate</code> (such as only year and month but no day in the month),
  72.  * or there may be inconsistent information (such as "Tuesday, July 15, 1996"
  73.  * -- July 15, 1996 is actually a Monday).
  74.  *
  75.  * <p>
  76.  * <strong>Insufficient information.</strong> The calendar will use default
  77.  * information to specify the missing fields. This may vary by calendar; for
  78.  * the Gregorian calendar, the default for a field is the same as that of the
  79.  * start of the epoch: i.e., YEAR = 1970, MONTH = JANUARY, DATE = 1, etc.
  80.  *
  81.  * <p>
  82.  * <strong>Inconsistent information.</strong> If fields conflict, the calendar
  83.  * will give preference to fields set more recently. For example, when
  84.  * determining the day, the calendar will look for one of the following
  85.  * combinations of fields.  The most recent combination, as determined by the
  86.  * most recently set single field, will be used.
  87.  *
  88.  * <blockquote>
  89.  * <pre>
  90.  * MONTH + DAY_OF_MONTH
  91.  * MONTH + WEEK_OF_MONTH + DAY_OF_WEEK
  92.  * MONTH + DAY_OF_WEEK_IN_MONTH + DAY_OF_WEEK
  93.  * DAY_OF_YEAR
  94.  * DAY_OF_WEEK + WEEK_OF_YEAR
  95.  * </pre>
  96.  * </blockquote>
  97.  *
  98.  * For the time of day:
  99.  *
  100.  * <blockquote>
  101.  * <pre>
  102.  * HOUR_OF_DAY
  103.  * AM_PM + HOUR
  104.  * </pre>
  105.  * </blockquote>
  106.  *
  107.  * <p>
  108.  * <strong>Note:</strong> for some non-Gregorian calendars, different
  109.  * fields may be necessary for complete disambiguation. For example, a full
  110.  * specification of the historial Arabic astronomical calendar requires year,
  111.  * month, day-of-month <em>and</em> day-of-week in some cases.
  112.  *
  113.  * <p>
  114.  * <strong>Note:</strong> There are certain possible ambiguities in
  115.  * interpretation of certain singular times, which are resolved in the
  116.  * following ways:
  117.  * <ol>
  118.  *     <li> 24:00:00 "belongs" to the following day. That is,
  119.  *          23:59 on Dec 31, 1969 < 24:00 on Jan 1, 1970 < 24:01:00 on Jan 1, 1970
  120.  *
  121.  *     <li> Although historically not precise, midnight also belongs to "am",
  122.  *          and noon belongs to "pm", so on the same day,
  123.  *          12:00 am (midnight) < 12:01 am, and 12:00 pm (noon) < 12:01 pm
  124.  * </ol>
  125.  *
  126.  * <p>
  127.  * The date or time format strings are not part of the definition of a
  128.  * calendar, as those must be modifiable or overridable by the user at
  129.  * runtime. Use {@link DateFormat}
  130.  * to format dates.
  131.  *
  132.  * <p>
  133.  * <code>Calendar</code> provides an API for field "rolling", where fields
  134.  * can be incremented or decremented, but wrap around. For example, rolling the
  135.  * month up in the date <code>December 12, <b>1996</b></code> results in
  136.  * <code>January 12, <b>1996</b></code>.
  137.  *
  138.  * <p>
  139.  * <code>Calendar</code> also provides a date arithmetic function for
  140.  * adding the specified (signed) amount of time to a particular time field.
  141.  * For example, subtracting 5 days from the date <code>September 12, 1996</code>
  142.  * results in <code>September 7, 1996</code>.
  143.  *
  144.  */
  145. class U_I18N_API Calendar {
  146. public:
  147.  
  148.     /**
  149.      * Field IDs for date and time. Used to specify date/time fields. ERA is calendar
  150.      * specific. Example ranges given are for illustration only; see specific Calendar
  151.      * subclasses for actual ranges.
  152.      */
  153.     enum EDateFields {
  154.         ERA,                  // Example: 0..1
  155.         YEAR,                 // Example: 1..big number
  156.         MONTH,                // Example: 0..11
  157.         WEEK_OF_YEAR,         // Example: 1..53
  158.         WEEK_OF_MONTH,        // Example: 1..4
  159.         DATE,                 // Example: 1..31
  160.         DAY_OF_YEAR,          // Example: 1..365
  161.         DAY_OF_WEEK,          // Example: 1..7
  162.         DAY_OF_WEEK_IN_MONTH, // Example: 1..4, may be specified as -1
  163.         AM_PM,                // Example: 0..1
  164.         HOUR,                 // Example: 0..11
  165.         HOUR_OF_DAY,          // Example: 0..23
  166.         MINUTE,               // Example: 0..59
  167.         SECOND,               // Example: 0..59
  168.         MILLISECOND,          // Example: 0..999
  169.         ZONE_OFFSET,          // Example: -12*U_MILLIS_PER_HOUR..12*U_MILLIS_PER_HOUR
  170.         DST_OFFSET,           // Example: 0 or U_MILLIS_PER_HOUR
  171.         FIELD_COUNT,
  172.  
  173.         DAY_OF_MONTH = DATE   // Synonyms
  174.     };
  175.  
  176.     /**
  177.      * Useful constant for days of week. Note: Calendar day-of-week is 1-based. Clients
  178.      * who create locale resources for the field of first-day-of-week should be aware of
  179.      * this. For instance, in US locale, first-day-of-week is set to 1, i.e., SUNDAY.
  180.      */
  181.     enum EDaysOfWeek {
  182.         SUNDAY = 1,
  183.         MONDAY,
  184.         TUESDAY,
  185.         WEDNESDAY,
  186.         THURSDAY,
  187.         FRIDAY,
  188.         SATURDAY
  189.     };
  190.  
  191.     /**
  192.      * Useful constants for month. Note: Calendar month is 0-based.
  193.      */
  194.     enum EMonths {
  195.         JANUARY,
  196.         FEBRUARY,
  197.         MARCH,
  198.         APRIL,
  199.         MAY,
  200.         JUNE,
  201.         JULY,
  202.         AUGUST,
  203.         SEPTEMBER,
  204.         OCTOBER,
  205.         NOVEMBER,
  206.         DECEMBER,
  207.         UNDECIMBER
  208.     };
  209.  
  210.     /**
  211.      * Useful constants for hour in 12-hour clock. Used in GregorianCalendar.
  212.      */
  213.     enum EAmpm {
  214.         AM,
  215.         PM
  216.     };
  217.  
  218.     /**
  219.      * destructor
  220.      */
  221.     virtual ~Calendar();
  222.  
  223.     /**
  224.      * Create and return a polymorphic copy of this calendar.
  225.      */
  226.     virtual Calendar* clone(void) const = 0;
  227.  
  228.     /**
  229.      * Creates a Calendar using the default timezone and locale. Clients are responsible
  230.      * for deleting the object returned.
  231.      *
  232.      * @param success  Indicates the success/failure of Calendar creation. Filled in
  233.      *                 with U_ZERO_ERROR if created successfully, set to a failure result
  234.      *                 otherwise.
  235.      * @return         A Calendar if created successfully. NULL otherwise.
  236.      */
  237.     static Calendar* createInstance(UErrorCode& success);
  238.  
  239.     /**
  240.      * Creates a Calendar using the given timezone and the default locale.
  241.      * The Calendar takes ownership of zoneToAdopt; the
  242.      * client must not delete it.
  243.      *
  244.      * @param zoneToAdopt  The given timezone to be adopted.
  245.      * @param success      Indicates the success/failure of Calendar creation. Filled in
  246.      *                     with U_ZERO_ERROR if created successfully, set to a failure result
  247.      *                     otherwise.
  248.      * @return             A Calendar if created successfully. NULL otherwise.
  249.      */
  250.     static Calendar* createInstance(TimeZone* zoneToAdopt, UErrorCode& success);
  251.  
  252.     /**
  253.      * Creates a Calendar using the given timezone and the default locale.  The TimeZone
  254.      * is _not_ adopted; the client is still responsible for deleting it.
  255.      *
  256.      * @param zone  The timezone.
  257.      * @param success      Indicates the success/failure of Calendar creation. Filled in
  258.      *                     with U_ZERO_ERROR if created successfully, set to a failure result
  259.      *                     otherwise.
  260.      * @return             A Calendar if created successfully. NULL otherwise.
  261.      */
  262.     static Calendar* createInstance(const TimeZone& zone, UErrorCode& success);
  263.  
  264.     /**
  265.      * Creates a Calendar using the default timezone and the given locale.
  266.      *
  267.      * @param aLocale  The given locale.
  268.      * @param success  Indicates the success/failure of Calendar creation. Filled in
  269.      *                 with U_ZERO_ERROR if created successfully, set to a failure result
  270.      *                 otherwise.
  271.      * @return         A Calendar if created successfully. NULL otherwise.
  272.      */
  273.     static Calendar* createInstance(const Locale& aLocale, UErrorCode& success);
  274.  
  275.     /**
  276.      * Creates a Calendar using the given timezone and given locale.
  277.      * The Calendar takes ownership of zoneToAdopt; the
  278.      * client must not delete it.
  279.      *
  280.      * @param zoneToAdopt  The given timezone to be adopted.
  281.      * @param aLocale      The given locale.
  282.      * @param success      Indicates the success/failure of Calendar creation. Filled in
  283.      *                     with U_ZERO_ERROR if created successfully, set to a failure result
  284.      *                     otherwise.
  285.      * @return             A Calendar if created successfully. NULL otherwise.
  286.      */
  287.     static Calendar* createInstance(TimeZone* zoneToAdopt, const Locale& aLocale, UErrorCode& success);
  288.  
  289.     /**
  290.      * Gets a Calendar using the given timezone and given locale.  The TimeZone
  291.      * is _not_ adopted; the client is still responsible for deleting it.
  292.      *
  293.      * @param zone  The timezone.
  294.      * @param aLocale      The given locale.
  295.      * @param success      Indicates the success/failure of Calendar creation. Filled in
  296.      *                     with U_ZERO_ERROR if created successfully, set to a failure result
  297.      *                     otherwise.
  298.      * @return             A Calendar if created successfully. NULL otherwise.
  299.      */
  300.     static Calendar* createInstance(const TimeZone& zoneToAdopt, const Locale& aLocale, UErrorCode& success);
  301.  
  302.     /**
  303.      * Returns a list of the locales for which Calendars are installed.
  304.      *
  305.      * @param count  Number of locales returned.
  306.      * @return       An array of Locale objects representing the set of locales for which
  307.      *               Calendars are installed.  The system retains ownership of this list;
  308.      *               the caller must NOT delete it.
  309.      */
  310.     static const Locale* getAvailableLocales(int32_t& count);
  311.  
  312.     /**
  313.      * Returns the current UTC (GMT) time measured in milliseconds since 0:00:00 on 1/1/70 
  314.      * (derived from the system time).
  315.      *
  316.      * @return   The current UTC time in milliseconds.
  317.      */
  318.     static UDate getNow(void);
  319.  
  320.     /**
  321.      * Gets this Calendar's time as milliseconds. May involve recalculation of time due
  322.      * to previous calls to set time field values. The time specified is non-local UTC
  323.      * (GMT) time. Although this method is const, this object may actually be changed
  324.      * (semantically const).
  325.      *
  326.      * @param status  Output param set to success/failure code on exit. If any value
  327.      *                previously set in the time field is invalid or restricted by
  328.      *                leniency, this will be set to an error status.
  329.      * @return        The current time in UTC (GMT) time, or zero if the operation
  330.      *                failed.
  331.      */
  332.     inline UDate getTime(UErrorCode& status) const { return getTimeInMillis(status); }
  333.  
  334.     /**
  335.      * Sets this Calendar's current time with the given UDate. The time specified should
  336.      * be in non-local UTC (GMT) time.
  337.      *
  338.      * @param date  The given UDate in UTC (GMT) time.
  339.      */
  340.     inline void setTime(UDate date, UErrorCode& status) { setTimeInMillis(date, status); }
  341.  
  342.     /**
  343.      * Compares the equality of two Calendar objects. Objects of different subclasses
  344.      * are considered unequal. This comparison is very exacting; two Calendar objects
  345.      * must be in exactly the same state to be considered equal. To compare based on the
  346.      * represented time, use equals() instead.
  347.      *
  348.      * @param that  The Calendar object to be compared with.
  349.      * @return      True if the given Calendar is the same as this Calendar; false
  350.      *              otherwise.
  351.      */
  352.     virtual bool_t operator==(const Calendar& that) const;
  353.  
  354.     /**
  355.      * Compares the inequality of two Calendar objects.
  356.      *
  357.      * @param that  The Calendar object to be compared with.
  358.      * @return      True if the given Calendar is not the same as this Calendar; false
  359.      *              otherwise.
  360.      */
  361.     bool_t operator!=(const Calendar& that) const {return !operator==(that);}
  362.  
  363.     /**
  364.      * Compares the Calendar time, whereas Calendar::operator== compares the equality of
  365.      * Calendar objects.
  366.      *
  367.      * @param when    The Calendar to be compared with this Calendar. Although this is a
  368.      *                const parameter, the object may be modified physically
  369.      *                (semantically const).
  370.      * @param status  Output param set to success/failure code on exit. If any value
  371.      *                previously set in the time field is invalid or restricted by
  372.      *                leniency, this will be set to an error status.
  373.      * @return        True if the current time of this Calendar is equal to the time of
  374.      *                Calendar when; false otherwise.
  375.      */
  376.     bool_t equals(const Calendar& when, UErrorCode& status) const;
  377.  
  378.     /**
  379.      * Returns true if this Calendar's current time is before "when"'s current time.
  380.      *
  381.      * @param when    The Calendar to be compared with this Calendar. Although this is a
  382.      *                const parameter, the object may be modified physically
  383.      *                (semantically const).
  384.      * @param status  Output param set to success/failure code on exit. If any value
  385.      *                previously set in the time field is invalid or restricted by
  386.      *                leniency, this will be set to an error status.
  387.      * @return        True if the current time of this Calendar is before the time of
  388.      *                Calendar when; false otherwise.
  389.      */
  390.     bool_t before(const Calendar& when, UErrorCode& status) const;
  391.  
  392.     /**
  393.      * Returns true if this Calendar's current time is after "when"'s current time.
  394.      *
  395.      * @param when    The Calendar to be compared with this Calendar. Although this is a
  396.      *                const parameter, the object may be modified physically
  397.      *                (semantically const).
  398.      * @param status  Output param set to success/failure code on exit. If any value
  399.      *                previously set in the time field is invalid or restricted by
  400.      *                leniency, this will be set to an error status.
  401.      * @return        True if the current time of this Calendar is after the time of
  402.      *                Calendar when; false otherwise.
  403.      */
  404.     bool_t after(const Calendar& when, UErrorCode& status) const;
  405.  
  406.     /**
  407.      * Return true if another Calendar object is equivalent to this one.  An equivalent
  408.      * Calendar will behave exactly as this one does, but may be set to a different time.
  409.      */
  410.      // {sfb} not in Java API!
  411.     virtual bool_t equivalentTo(const Calendar& other) const;
  412.  
  413.     /**
  414.      * UDate Arithmetic function. Adds the specified (signed) amount of time to the given
  415.      * time field, based on the calendar's rules. For example, to subtract 5 days from
  416.      * the current time of the calendar, call add(Calendar::DATE, -5). When adding on
  417.      * the month or Calendar::MONTH field, other fields like date might conflict and
  418.      * need to be changed. For instance, adding 1 month on the date 01/31/96 will result
  419.      * in 02/29/96.
  420.      *
  421.      * @param field   Specifies which date field to modify.
  422.      * @param amount  The amount of time to be added to the field, in the natural unit
  423.      *                for that field (e.g., days for the day fields, hours for the hour
  424.      *                field.)
  425.      * @param status  Output param set to success/failure code on exit. If any value
  426.      *                previously set in the time field is invalid or restricted by
  427.      *                leniency, this will be set to an error status.
  428.      */
  429.     virtual void add(EDateFields field, int32_t amount, UErrorCode& status) = 0;
  430.  
  431.     /**
  432.      * Time Field Rolling function. Rolls (up/down) a single unit of time on the given
  433.      * time field. For example, to roll the current date up by one day, call
  434.      * roll(Calendar::DATE, true). When rolling on the year or Calendar::YEAR field, it
  435.      * will roll the year value in the range between getMinimum(Calendar::YEAR) and the
  436.      * value returned by getMaximum(Calendar::YEAR). When rolling on the month or
  437.      * Calendar::MONTH field, other fields like date might conflict and, need to be
  438.      * changed. For instance, rolling the month up on the date 01/31/96 will result in
  439.      * 02/29/96. Rolling up always means rolling forward in time; e.g., rolling the year
  440.      * up on "100 BC" will result in "99 BC", for Gregorian calendar. When rolling on the
  441.      * hour-in-day or Calendar::HOUR_OF_DAY field, it will roll the hour value in the range
  442.      * between 0 and 23, which is zero-based.
  443.      * <P>
  444.      * NOTE: Do not use this method -- use roll(EDateFields, int, UErrorCode&) instead.
  445.      *
  446.      * @param field   The time field.
  447.      * @param up      Indicates if the value of the specified time field is to be rolled
  448.      *                up or rolled down. Use true if rolling up, false otherwise.
  449.      * @param status  Output param set to success/failure code on exit. If any value
  450.      *                previously set in the time field is invalid or restricted by
  451.      *                leniency, this will be set to an error status.
  452.      */
  453.     // {sfb} this doesn't seem to match the Java version
  454.     void roll(EDateFields field, bool_t up, UErrorCode& status);
  455.  
  456.     /**
  457.      * Time Field Rolling function. Rolls by the given amount on the given
  458.      * time field. For example, to roll the current date up by one day, call
  459.      * roll(Calendar::DATE, +1, status). When rolling on the month or
  460.      * Calendar::MONTH field, other fields like date might conflict and, need to be
  461.      * changed. For instance, rolling the month up on the date 01/31/96 will result in
  462.      * 02/29/96.  Rolling by a positive value always means rolling forward in time;
  463.      * e.g., rolling the year by +1 on "100 BC" will result in "99 BC", for Gregorian
  464.      * calendar. When rolling on the hour-in-day or Calendar::HOUR_OF_DAY field, it will
  465.      * roll the hour value in the range between 0 and 23, which is zero-based.
  466.      * <P>
  467.      * The only difference between roll() and add() is that roll() does not change
  468.      * the value of more significant fields when it reaches the minimum or maximum
  469.      * of its range, whereas add() does.
  470.      *
  471.      * @param field   The time field.
  472.      * @param amount  Indicates amount to roll.
  473.      * @param status  Output param set to success/failure code on exit. If any value
  474.      *                previously set in the time field is invalid, this will be set to
  475.      *                an error status.
  476.      */
  477.     // {sfb} this doesn't match Java- but it has to be this way to assure backwards compatibility
  478.     virtual void roll(EDateFields field, int32_t amount, UErrorCode& status) = 0;
  479.  
  480.     /**
  481.      * Sets the calendar's time zone to be the one passed in. The Calendar takes ownership
  482.      * of the TimeZone; the caller is no longer responsible for deleting it.  If the
  483.      * given time zone is NULL, this function has no effect.
  484.      *
  485.      * @param value  The given time zone.
  486.      */
  487.     void adoptTimeZone(TimeZone* value);
  488.  
  489.     /**
  490.      * Sets the calendar's time zone to be the same as the one passed in. The TimeZone
  491.      * passed in is _not_ adopted; the client is still responsible for deleting it.
  492.      *
  493.      * @param value  The given time zone.
  494.      */
  495.     void setTimeZone(const TimeZone& zone);
  496.  
  497.     /**
  498.      * Returns a reference to the time zone owned by this calendar. The returned reference
  499.      * is only valid until clients make another call to adoptTimeZone or setTimeZone,
  500.      * or this Calendar is destroyed.
  501.      *
  502.      * @return   The time zone object associated with this calendar.
  503.      */
  504.     const TimeZone& getTimeZone(void) const;
  505.  
  506.     /**
  507.      * Returns the time zone owned by this calendar. The caller owns the returned object
  508.      * and must delete it when done.  After this call, the new time zone associated
  509.      * with this Calendar is the default TimeZone as returned by TimeZone::createDefault().
  510.      *
  511.      * @return   The time zone object which was associated with this calendar.
  512.      */
  513.     TimeZone* orphanTimeZone(void);
  514.  
  515.     /**
  516.      * Queries if the current date for this Calendar is in Daylight Savings Time.
  517.      *
  518.      * @param status Fill-in parameter which receives the status of this operation.
  519.      * @return   True if the current date for this Calendar is in Daylight Savings Time,
  520.      *           false, otherwise.
  521.      */
  522.     // {sfb} API change?
  523.     virtual bool_t inDaylightTime(UErrorCode& status) const = 0;
  524.  
  525.     /**
  526.      * Specifies whether or not date/time interpretation is to be lenient. With lenient
  527.      * interpretation, a date such as "February 942, 1996" will be treated as being
  528.      * equivalent to the 941st day after February 1, 1996. With strict interpretation,
  529.      * such dates will cause an error when computing time from the time field values
  530.      * representing the dates.
  531.      *
  532.      * @param lenient  True specifies date/time interpretation to be lenient.
  533.      *
  534.      * @see            DateFormat#setLenient
  535.      */
  536.     void setLenient(bool_t lenient);
  537.  
  538.     /**
  539.      * Tells whether date/time interpretation is to be lenient.
  540.      *
  541.      * @return   True tells that date/time interpretation is to be lenient.
  542.      */
  543.     bool_t isLenient(void) const;
  544.  
  545.     /**
  546.      * Sets what the first day of the week is; e.g., Sunday in US, Monday in France.
  547.      *
  548.      * @param value  The given first day of the week.
  549.      */
  550.     void setFirstDayOfWeek(EDaysOfWeek value);
  551.  
  552.     /**
  553.      * Gets what the first day of the week is; e.g., Sunday in US, Monday in France.
  554.      *
  555.      * @return   The first day of the week.
  556.      */
  557.     EDaysOfWeek getFirstDayOfWeek(void) const;
  558.  
  559.     /**
  560.      * Sets what the minimal days required in the first week of the year are; For
  561.      * example, if the first week is defined as one that contains the first day of the
  562.      * first month of a year, call the method with value 1. If it must be a full week,
  563.      * use value 7.
  564.      *
  565.      * @param value  The given minimal days required in the first week of the year.
  566.      */
  567.     void setMinimalDaysInFirstWeek(uint8_t value);
  568.  
  569.     /**
  570.      * Gets what the minimal days required in the first week of the year are; e.g., if
  571.      * the first week is defined as one that contains the first day of the first month
  572.      * of a year, getMinimalDaysInFirstWeek returns 1. If the minimal days required must
  573.      * be a full week, getMinimalDaysInFirstWeek returns 7.
  574.      *
  575.      * @return   The minimal days required in the first week of the year.
  576.      */
  577.     uint8_t getMinimalDaysInFirstWeek(void) const;
  578.  
  579.     /**
  580.      * Gets the minimum value for the given time field. e.g., for Gregorian
  581.      * DAY_OF_MONTH, 1.
  582.      *
  583.      * @param field  The given time field.
  584.      * @return       The minimum value for the given time field.
  585.      */
  586.     virtual int32_t getMinimum(EDateFields field) const = 0;
  587.  
  588.     /**
  589.      * Gets the maximum value for the given time field. e.g. for Gregorian DAY_OF_MONTH,
  590.      * 31.
  591.      *
  592.      * @param field  The given time field.
  593.      * @return       The maximum value for the given time field.
  594.      */
  595.     virtual int32_t getMaximum(EDateFields field) const = 0;
  596.  
  597.     /**
  598.      * Gets the highest minimum value for the given field if varies. Otherwise same as
  599.      * getMinimum(). For Gregorian, no difference.
  600.      *
  601.      * @param field  The given time field.
  602.      * @return       The highest minimum value for the given time field.
  603.      */
  604.     virtual int32_t getGreatestMinimum(EDateFields field) const = 0;
  605.  
  606.     /**
  607.      * Gets the lowest maximum value for the given field if varies. Otherwise same as
  608.      * getMaximum(). e.g., for Gregorian DAY_OF_MONTH, 28.
  609.      *
  610.      * @param field  The given time field.
  611.      * @return       The lowest maximum value for the given time field.
  612.      */
  613.     virtual int32_t getLeastMaximum(EDateFields field) const = 0;
  614.  
  615.     /**
  616.      * Return the minimum value that this field could have, given the current date.
  617.      * For the Gregorian calendar, this is the same as getMinimum() and getGreatestMinimum().
  618.      *
  619.      * The version of this function on Calendar uses an iterative algorithm to determine the
  620.      * actual minimum value for the field.  There is almost always a more efficient way to
  621.      * accomplish this (in most cases, you can simply return getMinimum()).  GregorianCalendar
  622.      * overrides this function with a more efficient implementation.
  623.      *
  624.      * @param field the field to determine the minimum of
  625.      * @return the minimum of the given field for the current date of this Calendar
  626.      */
  627.     int32_t getActualMinimum(EDateFields field, UErrorCode& status) const;
  628.  
  629.     /**
  630.      * Return the maximum value that this field could have, given the current date.
  631.      * For example, with the date "Feb 3, 1997" and the DAY_OF_MONTH field, the actual
  632.      * maximum would be 28; for "Feb 3, 1996" it s 29.  Similarly for a Hebrew calendar,
  633.      * for some years the actual maximum for MONTH is 12, and for others 13.
  634.      *
  635.      * The version of this function on Calendar uses an iterative algorithm to determine the
  636.      * actual maximum value for the field.  There is almost always a more efficient way to
  637.      * accomplish this (in most cases, you can simply return getMaximum()).  GregorianCalendar
  638.      * overrides this function with a more efficient implementation.
  639.      *
  640.      * @param field the field to determine the maximum of
  641.      * @return the maximum of the given field for the current date of this Calendar
  642.      */
  643.     int32_t getActualMaximum(EDateFields field, UErrorCode& status) const;
  644.  
  645.     /**
  646.      * Gets the value for a given time field. Recalculate the current time field values
  647.      * if the time value has been changed by a call to setTime(). Return zero for unset
  648.      * fields if any fields have been explicitly set by a call to set(). To force a
  649.      * recomputation of all fields regardless of the previous state, call complete().
  650.      * This method is semantically const, but may alter the object in memory.
  651.      *
  652.      * @param field  The given time field.
  653.      * @param status Fill-in parameter which receives the status of the operation.
  654.      * @return       The value for the given time field, or zero if the field is unset,
  655.      *               and set() has been called for any other field.
  656.      */
  657.     int32_t get(EDateFields field, UErrorCode& status) const;
  658.  
  659.     /**
  660.      * Determines if the given time field has a value set. This can affect in the
  661.      * resolving of time in Calendar. Unset fields have a value of zero, by definition.
  662.      *
  663.      * @return   True if the given time field has a value set; false otherwise.
  664.      */
  665.     bool_t isSet(EDateFields field) const;
  666.  
  667.     /**
  668.      * Sets the given time field with the given value.
  669.      *
  670.      * @param field  The given time field.
  671.      * @param value  The value to be set for the given time field.
  672.      */
  673.     void set(EDateFields field, int32_t value);
  674.  
  675.     /**
  676.      * Sets the values for the fields YEAR, MONTH, and DATE. Other field values are
  677.      * retained; call clear() first if this is not desired.
  678.      *
  679.      * @param year   The value used to set the YEAR time field.
  680.      * @param month  The value used to set the MONTH time field. Month value is 0-based.
  681.      *               e.g., 0 for January.
  682.      * @param date   The value used to set the DATE time field.
  683.      */
  684.     void set(int32_t year, int32_t month, int32_t date);
  685.  
  686.     /**
  687.      * Sets the values for the fields YEAR, MONTH, DATE, HOUR_OF_DAY, and MINUTE. Other
  688.      * field values are retained; call clear() first if this is not desired.
  689.      *
  690.      * @param year    The value used to set the YEAR time field.
  691.      * @param month   The value used to set the MONTH time field. Month value is
  692.      *                0-based. E.g., 0 for January.
  693.      * @param date    The value used to set the DATE time field.
  694.      * @param hour    The value used to set the HOUR_OF_DAY time field.
  695.      * @param minute  The value used to set the MINUTE time field.
  696.      */
  697.     void set(int32_t year, int32_t month, int32_t date, int32_t hour, int32_t minute);
  698.  
  699.     /**
  700.      * Sets the values for the fields YEAR, MONTH, DATE, HOUR_OF_DAY, MINUTE, and SECOND.
  701.      * Other field values are retained; call clear() first if this is not desired.
  702.      *
  703.      * @param year    The value used to set the YEAR time field.
  704.      * @param month   The value used to set the MONTH time field. Month value is
  705.      *                0-based. E.g., 0 for January.
  706.      * @param date    The value used to set the DATE time field.
  707.      * @param hour    The value used to set the HOUR_OF_DAY time field.
  708.      * @param minute  The value used to set the MINUTE time field.
  709.      * @param second  The value used to set the SECOND time field.
  710.      */
  711.     void set(int32_t year, int32_t month, int32_t date, int32_t hour, int32_t minute, int32_t second);
  712.  
  713.     /**
  714.      * Clears the values of all the time fields, making them both unset and assigning
  715.      * them a value of zero. The field values will be determined during the next
  716.      * resolving of time into time fields.
  717.      */
  718.     void clear(void);
  719.  
  720.     /**
  721.      * Clears the value in the given time field, both making it unset and assigning it a
  722.      * value of zero. This field value will be determined during the next resolving of
  723.      * time into time fields.
  724.      *
  725.      * @param field  The time field to be cleared.
  726.      */
  727.     void clear(EDateFields field);
  728.  
  729.     /**
  730.      * Returns a unique class ID POLYMORPHICALLY. Pure virtual method. This method is to
  731.      * implement a simple version of RTTI, since not all C++ compilers support genuine
  732.      * RTTI. Polymorphic operator==() and clone() methods call this method.
  733.      * <P>
  734.      * Concrete subclasses of Calendar must implement getDynamicClassID() and also a
  735.      * static method and data member:
  736.      *
  737.      *      static UClassID getStaticClassID() { return (UClassID)&fgClassID; }
  738.      *      static char fgClassID;
  739.      *
  740.      * @return   The class ID for this object. All objects of a given class have the
  741.      *           same class ID. Objects of other classes have different class IDs.
  742.      */
  743.     virtual UClassID getDynamicClassID(void) const = 0;
  744.  
  745. protected:
  746.  
  747.      /**
  748.       * Constructs a Calendar with the default time zone as returned by
  749.       * TimeZone::createInstance(), and the default locale.
  750.       *
  751.       * @param success  Indicates the status of Calendar object construction. Returns
  752.       *                 U_ZERO_ERROR if constructed successfully.
  753.       */
  754.     Calendar(UErrorCode& success);
  755.  
  756.     /**
  757.      * Copy constructor
  758.      */
  759.     Calendar(const Calendar& source);
  760.  
  761.     /**
  762.      * Default assignment operator
  763.      */
  764.     Calendar& operator=(const Calendar& right);
  765.  
  766.     /**
  767.      * Constructs a Calendar with the given time zone and locale. Clients are no longer
  768.      * responsible for deleting the given time zone object after it's adopted.
  769.      *
  770.      * @param zoneToAdopt     The given time zone.
  771.      * @param aLocale  The given locale.
  772.      * @param success  Indicates the status of Calendar object construction. Returns
  773.      *                 U_ZERO_ERROR if constructed successfully.
  774.      */
  775.     Calendar(TimeZone* zone, const Locale& aLocale, UErrorCode& success);
  776.  
  777.     /**
  778.      * Constructs a Calendar with the given time zone and locale.
  779.      *
  780.      * @param zone     The given time zone.
  781.      * @param aLocale  The given locale.
  782.      * @param success  Indicates the status of Calendar object construction. Returns
  783.      *                 U_ZERO_ERROR if constructed successfully.
  784.      */
  785.     Calendar(const TimeZone& zone, const Locale& aLocale, UErrorCode& success);
  786.  
  787.     /**
  788.      * Converts Calendar's time field values to GMT as milliseconds.
  789.      *
  790.      * @param status  Output param set to success/failure code on exit. If any value
  791.      *                previously set in the time field is invalid or restricted by
  792.      *                leniency, this will be set to an error status.
  793.      */
  794.     virtual void computeTime(UErrorCode& status) = 0;
  795.  
  796.     /**
  797.      * Converts GMT as milliseconds to time field values. This allows you to sync up the
  798.      * time field values with a new time that is set for the calendar.  This method
  799.      * does NOT recompute the time first; to recompute the time, then the fields, use
  800.      * the method complete().
  801.      */
  802.     virtual void computeFields(UErrorCode& status) = 0;
  803.  
  804.     // {sfb} this uses a long in Java
  805.     /**
  806.      * Gets this Calendar's current time as a long.
  807.      * @return the current time as UTC milliseconds from the epoch.
  808.      */
  809.     double getTimeInMillis(UErrorCode& status) const;
  810.  
  811.     /**
  812.      * Sets this Calendar's current time from the given long value.
  813.      * @param date the new time in UTC milliseconds from the epoch.
  814.      */
  815.     void setTimeInMillis( double millis, UErrorCode& status );
  816.  
  817.     /**
  818.      * Recomputes the current time from currently set fields, and then fills in any
  819.      * unset fields in the time field list.
  820.      *
  821.      * @param status  Output param set to success/failure code on exit. If any value
  822.      *                previously set in the time field is invalid or restricted by
  823.      *                leniency, this will be set to an error status.
  824.      */
  825.     void complete(UErrorCode& status);
  826.  
  827.     /**
  828.      * Gets the value for a given time field. Subclasses can use this function to get
  829.      * field values without forcing recomputation of time.
  830.      *
  831.      * @param field  The given time field.
  832.      * @return       The value for the given time field.
  833.      */
  834.     int32_t internalGet(EDateFields field) const {return fFields[field];}
  835.  
  836.     /**
  837.      * Sets the value for a given time field.  This is a fast internal method for
  838.      * subclasses.  It does not affect the areFieldsInSync, isTimeSet, or areAllFieldsSet
  839.      * flags.
  840.      */
  841.     void internalSet(EDateFields field, int32_t value);
  842.  
  843. protected:
  844.     /**
  845.      * The flag which indicates if the current time is set in the calendar.
  846.      */
  847.     bool_t      fIsTimeSet;
  848.  
  849.     /**
  850.      * True if the fields are in sync with the currently set time of this Calendar.
  851.      * If false, then the next attempt to get the value of a field will
  852.      * force a recomputation of all fields from the current value of the time
  853.      * field.
  854.      * <P>
  855.      * This should really be named areFieldsInSync, but the old name is retained
  856.      * for backward compatibility.
  857.      */
  858.     bool_t      fAreFieldsSet;
  859.  
  860.     /**
  861.      * True if all of the fields have been set.  This is initially false, and set to
  862.      * true by computeFields().
  863.      */
  864.     bool_t      fAreAllFieldsSet;
  865.  
  866.     /**
  867.      * Get the current time without recomputing.
  868.      */
  869.     UDate        internalGetTime(void) const     { return fTime; }
  870.  
  871.     /**
  872.      * Set the current time without affecting flags or fields.
  873.      */
  874.     void        internalSetTime(UDate time)     { fTime = time; }
  875.  
  876.     /**
  877.      * The time fields containing values into which the millis is computed.
  878.      */
  879.     int32_t     fFields[FIELD_COUNT];
  880.  
  881.     /**
  882.      * The flags which tell if a specified time field for the calendar is set.
  883.      */
  884.     bool_t      fIsSet[FIELD_COUNT];
  885.  
  886.     // Special values of stamp[]
  887.     enum EStampValues {
  888.         kUnset                 = 0,
  889.         kInternallySet,
  890.         kMinimumUserStamp
  891.     };
  892.  
  893.     /**
  894.      * Pseudo-time-stamps which specify when each field was set. There
  895.      * are two special values, UNSET and INTERNALLY_SET. Values from
  896.      * MINIMUM_USER_SET to Integer.MAX_VALUE are legal user set values.
  897.      */
  898.     int32_t        fStamp[FIELD_COUNT];
  899.  
  900. private:
  901.  
  902.     // The next available value for stampp[]
  903.     int32_t fNextStamp;// = MINIMUM_USER_STAMP;
  904.  
  905.     /**
  906.      * The current time set for the calendar.
  907.      */
  908.     UDate        fTime;
  909.  
  910.     /**
  911.      * @see   #setLenient
  912.      */
  913.     bool_t      fLenient;
  914.  
  915.     /**
  916.      * Time zone affects the time calculation done by Calendar. Calendar subclasses use
  917.      * the time zone data to produce the local time.
  918.      */
  919.     TimeZone*   fZone;
  920.  
  921.     /**
  922.      * Both firstDayOfWeek and minimalDaysInFirstWeek are locale-dependent. They are
  923.      * used to figure out the week count for a specific date for a given locale. These
  924.      * must be set when a Calendar is constructed. For example, in US locale,
  925.      * firstDayOfWeek is SUNDAY; minimalDaysInFirstWeek is 1. They are used to figure
  926.      * out the week count for a specific date for a given locale. These must be set when
  927.      * a Calendar is constructed.
  928.      */
  929.     EDaysOfWeek fFirstDayOfWeek;
  930.     uint8_t     fMinimalDaysInFirstWeek;
  931.  
  932.     /**
  933.      * Sets firstDayOfWeek and minimalDaysInFirstWeek. Called at Calendar construction
  934.      * time.
  935.      *
  936.      * @param desiredLocale  The given locale.
  937.      * @param success        Indicates the status of setting the week count data from
  938.      *                       the resource for the given locale. Returns U_ZERO_ERROR if
  939.      *                       constructed successfully.
  940.      */
  941.     void        setWeekCountData(const Locale& desiredLocale, UErrorCode& success);
  942.  
  943.     /**
  944.      * Recompute the time and update the status fields isTimeSet
  945.      * and areFieldsSet.  Callers should check isTimeSet and only
  946.      * call this method if isTimeSet is false.
  947.      */
  948.     void updateTime(UErrorCode& status);
  949.  
  950.     /**
  951.      * Convert a UnicodeString to a long integer, using the standard C library. Return
  952.      * both the value obtained, and a UErrorCode indicating success or failure. We fail
  953.      * if the string is zero length, of if strtol() does not parse all of the characters
  954.      * in the string, or if the value is not in the range 1..7.
  955.      */
  956.     static int32_t  stringToDayNumber(const UnicodeString& string, UErrorCode& status);
  957.  
  958.     /**
  959.      * The resource tag for the resource where the week-count data is stored.
  960.      */
  961.     static const char* kDateTimeElements;
  962. };
  963.  
  964. // -------------------------------------
  965.  
  966. inline Calendar*
  967. Calendar::createInstance(TimeZone* zone, UErrorCode& errorCode)
  968. {
  969.     // since the Locale isn't specified, use the default locale
  970.     return createInstance(zone, Locale::getDefault(), errorCode);
  971. }
  972.  
  973. // -------------------------------------
  974.  
  975. inline void 
  976. Calendar::roll(EDateFields field, bool_t up, UErrorCode& status)
  977. {
  978.     roll(field, (int32_t)(up ? +1 : -1), status);
  979. }
  980.  
  981. // -------------------------------------
  982.  
  983. /**
  984.  * Fast method for subclasses.  The caller must maintain fUserSetDSTOffset and
  985.  * fUserSetZoneOffset, as well as the isSet[] array.
  986.  */
  987. inline void
  988. Calendar::internalSet(EDateFields field, int32_t value)
  989. {
  990.     fFields[field] = value;
  991. }
  992.  
  993. #endif // _CALENDAR
  994.